//
//  YijianfankuiViewController.m
//  jizhiyunduan
//
//  Created by 鞠超 on 16/4/28.
//  Copyright © 2016年 JC. All rights reserved.
//

#import "YijianfankuiViewController.h"

@interface YijianfankuiViewController () <UITextViewDelegate, UIScrollViewDelegate>

@property (nonatomic, strong) UIScrollView * scrollView;

@property (nonatomic, strong) UITextView * text;

@property (nonatomic, strong) UILabel * lbl;

@end

@implementation YijianfankuiViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void)p_navi
{
    _lblTitle.text = [NSString stringWithFormat:@"发表意见"];
    _lblTitle.font = [UIFont systemFontOfSize:20];
    
    _lblRight.text = @"发表";
    
    [self addLeftButton:@"fanhui@2x.png"];
}

//左返回
- (void)clickLeftButton:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//发表
- (void)clickRightButton:(UIButton *)sender
{
    [self.text resignFirstResponder];
    
    if([self.text.text length] == 0)
    {
        UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"发表的意见不能为空" preferredStyle:(UIAlertControllerStyleAlert)];
        
        [self presentViewController:alert animated:YES completion:^{
            
        }];
        
        UIAlertAction * action = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        
        [alert addAction:action];
    }
    else
    {
        
    }
}

//隐藏tabbar
-(void)viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void)p_setupView
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64)];
    self.scrollView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.scrollView.contentSize = CGSizeMake(0, SCREEN_HEIGHT - 60);
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.delegate = self;
    
    [self.view addSubview:self.scrollView];
    

    //text
    self.text = [[UITextView alloc] initWithFrame:CGRectMake(0, 10, SCREEN_WIDTH, 200)];
    self.text.backgroundColor = [UIColor whiteColor];
    self.text.font = [UIFont systemFontOfSize:17];
    self.text.delegate = self;

    [self.scrollView addSubview:self.text];
    
    self.lbl = [[UILabel alloc] initWithFrame:CGRectMake(5, 21, SCREEN_WIDTH, 15)];
    self.lbl.text = @"请写下您宝贵的意见";
    self.lbl.textColor = [UIColor grayColor];
    self.lbl.font = [UIFont systemFontOfSize:17];
    [self.scrollView addSubview:self.lbl];
    
    
}

#pragma mark - textView点击
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    if([self.text.text length] == 0)
    {
        self.lbl.hidden = NO;
    }
    
    [self.text resignFirstResponder];
}

- (BOOL)textViewShouldBeginEditing:(UITextView *)textView
{
    self.lbl.hidden = YES;
    
    return YES;
}

#pragma mark - scrollView代理
- (void )scrollViewDidScroll:(UIScrollView *)scrollView
{
    if([self.text.text length] == 0)
    {
        self.lbl.hidden = NO;
    }
    
    [self.text resignFirstResponder];
}





@end
